#include "Button.h"
#include "../nclgl/OBJMesh.h"
#include "Renderer.h"
#include "HUDManager.h"


Button::Button(Vector3 position,float size,void (HUDManager::*function)(void))
{
	textured = false;
	selected = false;

	cube = Mesh::GenerateQuad();
	button.SetMesh(cube);
	button.SetColour(Vector4(1,1,1,1));
	button.SetModelScale(Vector3(size*4,size,1));
	button.SetTransform(Matrix4::Translation(position));

	p_function = function;
}

Button::~Button()
{
	delete cube;
}

void Button::Execute()
{
	if(p_function)
	{
		(HUDManager::GetInstance()->*(this->p_function))();
	}
}

//sets Textures
void Button::SetTextures(string standardtex,string selectedtex)
{
	StandardTex = (SOIL_load_OGL_texture(selectedtex.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));
	SelectedTex = (SOIL_load_OGL_texture(standardtex.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS));

	textured = true;

	button.SetColour(Vector4(1,1,1,1));

	if(selected)
	{
		button.GetMesh()->SetTexture(StandardTex);
	}
	else
	{
		button.GetMesh()->SetTexture(SelectedTex);
	}


}

void Button::ToggleSelected()
{
	selected = !selected;

	if(textured)
	{
		if(selected)
		{
			button.GetMesh()->SetTexture(StandardTex);


		}
		else
		{
			button.GetMesh()->SetTexture(SelectedTex);

		}
	}
	else
	{
		if(selected)
		{
			button.SetColour(Vector4(0,255,0,1));
		}
		else
		{
			button.SetColour(Vector4(1,1,1,1));
		}
	}

}
